package com.blb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blb.entity.Settlement;
import com.blb.entity.User;
import com.blb.entity.page.BlbPage;
import com.blb.entity.page.DataTablePage;
import com.blb.service.ISettlementService;
import com.blb.utils.ResponseHelp;
import com.blb.utils.ShiroUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yanghao
 * @since 2019-11-22
 */
@Controller
@RequestMapping("/settlement")
public class SettlementController {

    public static int count;

    @Resource
    private ISettlementService iSettlementService;

    @RequestMapping("{page}")
    public String wel(@PathVariable String page){
        return "logistics/"+ page;
    }

    @ResponseBody
    @RequestMapping("findAll")
    public BlbPage findAllProduct(@RequestParam(required = false, value ="freightId") String freightId,  Integer start, Integer length){
        System.out.println(freightId);
        User user = ShiroUtils.getUser();
        String companyId = user.getCompanyId();
        List<Settlement> findall = iSettlementService.findAll( freightId,companyId, start, length);
        /*查询分页数据*/

        System.out.println(findall);

        count = iSettlementService.getAllCount(freightId,companyId);

        return new DataTablePage(count,count,findall);
    }

    @ResponseBody
    @RequestMapping("findsettlementStatus")
    public ResponseHelp findSettlementStatus(){

        Integer count1 = iSettlementService.count(new QueryWrapper<Settlement>().eq("Settlement_status", "1"));
        System.out.println(count1);
        System.out.println(count);
        int i =count-count1;
        List<Integer> listnum=new ArrayList<Integer>();
        listnum.add(count1);
        listnum.add(i);
        ResponseHelp responseHelp =new ResponseHelp();
        responseHelp.setData(listnum);
        return responseHelp;
    };

    @ResponseBody
    @RequestMapping("updatesettlement")
    public ResponseHelp updateSettlement(String id){
        System.out.println("结算进来了");
        iSettlementService.updateStatus(id);
        ResponseHelp responseHelp =new ResponseHelp();
        return responseHelp;
    }



}

